package com.hzxgs.tracelogstarter.config;

import cn.hutool.http.GlobalInterceptor;
import com.hzxgs.tracelogstarter.properties.TraceProperties;
import com.hzxgs.tracelogstarter.trace.HutoolHttpTraceInterceptor;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

@Component
@ConditionalOnClass(value = { GlobalInterceptor.class })
public class HutoolHttpConfig {

    @Resource
    private TraceProperties traceProperties;
    @Resource
    private HutoolHttpTraceInterceptor hutoolHttpTraceInterceptor;

    @Bean
    public void hutoolGlobalHeadersConfig() {
        if (traceProperties.getEnable()) {
            GlobalInterceptor.INSTANCE.addRequestInterceptor(hutoolHttpTraceInterceptor);
        }
    }
}
